package com.qlc.spring.cloud.demo.user;

import com.qlc.spring.cloud.demo.Result;
import com.qlc.spring.cloud.demo.user.VO.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Name:  UserConsumerController
 * User:  wang chang
 * CreateTime: 2019-05-28 16:41
 **/
@RestController
public class UserConsumerController {


    private static final String url = "http://localhost:8002";

    private static final String eUrl = "http://QLC-SPRING-CLOUD-DEMO-PROVIDER-USER";

    @Autowired
    RestTemplate restTemplate;


    @RequestMapping(value = "/s/n")
    public Result<UserVO> queryUserByCode() {

        return (Result<UserVO>) restTemplate.getForObject(url + "/test/net/0001", Result.class);
    }

    @RequestMapping(value = "/s/n1")
    public Result<UserVO> queryUserByCode1() {
        return restTemplate.getForObject(eUrl + "/test/net/0001", Result.class);
    }

    @RequestMapping(value = "s/n2")
    public Result<Void> addUser() {
        UserVO userVO = new UserVO();
        userVO.setUserCode("0002");
        userVO.setAge(35);
        userVO.setMobile("10000");
        return restTemplate.postForObject(url + "/test/add", userVO, Result.class);
    }

    @RequestMapping(value = "s/n3")
    public Result<Void> addUser1() {
        UserVO userVO = new UserVO();
        userVO.setUserCode("0003");
        userVO.setAge(36);
        userVO.setMobile("10086");
        return restTemplate.postForObject(eUrl + "/test/add", userVO, Result.class);
    }

}
